 <?php echo $this->Html->script(array('ckeditor/ckeditor')); ?>
          <?php echo $this->Form->create("Advert",array('type' => 'file'));
                echo $this->Form->hidden('id');

           ?>
          
             <fieldset>
              <div class="input-content">
                  <div class="input ">
                    <label for="last-name">Tên ảnh(<span>*</span>)</label>
                    <?php echo $this-> Form->input('advert_info',array('class'=>'placeholder','placeholder'=>' Tên ảnh','label'=>false,'div'=>false));?>
                    <div class="error-message" id="error_name"></div>
				
		          </div>
                  <div class="input">
                      <label for="last-name">Vị trí đặt(<span>*</span>)</label>
                      <?php
                      echo $this->Form->input('position', array(
                          'type' => 'select',
                          'options' => array('1'=>'Trên header','2'=>'Đầu mỗi trang'),
                          'empty' => 'Chọn loại vị trí',
                          'label' => false,
                          'div' => false,
                              )
                      );
                      ?>
                      <div class="error-message" id="errorPosition"></div>

                  </div>
                  <div class="input">
                    <label for="last-name">File ảnh(<span>*</span>)</label>
                    <?php
                    echo $this->Form->input('image', array(
                                      'type' => 'file',
                                      
                                      'label'=>false,
                                      'div'=>false,
									  'onChange'=>'return readURL(this)'
                                      
                                      
                                      
                                  )
                    ); ?>
					<div class="error-message" id="error_file"></div>
					<div style="clear:both;margin-left: 146px;padding-top: 10px;">
					<img id="image_show" src="<?php echo ( isset($this->request->data['Advert']['image']))?$this->request->data['Advert']['image']:"#"; ?>" alt="" width="200" height="150" />
					</div>
				   </div>
                  
                   
                  
                  <div class="submit">
                   <?php echo $this->Form->submit("",array('class'=>'save','id'=>'btnSave')); ?>
                   <!-- <input type="submit" id="btnSave" value="" class="save"> -->
                    <a href="javascript:resetForm()" id="resetForm" class="reset">Reset</a>
                  </div>
            </fieldset>
          <?php echo $this->Form->end(); ?>
    <script>
	function readURL(input) {
            if (input.files && input.files[0]) {
                var reader = new FileReader();

                reader.onload = function (e) {
                    $('#image_show')
                        .attr('src', e.target.result)
                        .width(200)
                    .height(200);
                };

              reader.readAsDataURL(input.files[0]);
            }
     }
    $("#btnSave").click(function(){
           var  validateAdvertName   = new validate("AdvertAdvertInfo","error_name","Bạn chưa nhập tên banner");
           var  validateFile       = new validate("AdvertFileName",'error_file',"Bạn chưa chọn file ảnh");
           var  validatePosition       = new validate("AdvertPosition",'errorPosition',"Bạn chưa chọn vị trí");
               
         var  result     = validateAdvertName.notEmpty();
           // var  result2    = validateFile.notEmpty();
            // var  result3    = validatePosition.notEmpty();
             alert(result);
             if(!(result ))
            {
                $('html, body').animate({ scrollTop: 0 }, 'slow');
            }
            return false ;
        });
     function resetForm()
     {
        window.location.reload();
     }
    </script>